package com.hongfasoft.servlet;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.hongfasoft.wx.service.CoreService;
import com.xinyusoft.dao.DAO;
import com.xinyusoft.util.Utility;
import com.xinyusoft.util.XMLProperties;

public class DAOInit extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void destroy() {
		DAO.clear();
	}

	public void init() throws ServletException {
		try {
			CoreService.realRoot = this.getServletConfig().getServletContext().getRealPath("/");
			File rootDir = Utility.getClassLocation().getParentFile();
			File configFile = new File(rootDir, "conf/jztj.xml");
			System.out.println(configFile.getAbsolutePath());
			if (!configFile.exists())
			{
				System.out.println("conf找不到文件jztj.xml");
			}
			XMLProperties ps = new XMLProperties(configFile);
			DAO.init(ps);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}